<template>
  <div>
    <el-table :data="tableData ? tableData : []" style="width: 100%">
      <el-table-column prop="id" label="角色编号" width="180">
      </el-table-column>
      <el-table-column prop="rolename" label="角色名称" width="180">
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="obj">
          <el-button type="success" v-show="obj.row.status == 1" round
            >启用中</el-button
          >
          <el-button type="danger" v-show="obj.row.status == 2" round
            >已禁用</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="obj">
          <el-button
            type="primary"
            icon="el-icon-edit"
            circle
            @click="updateRole(obj.row.id)"
          ></el-button>
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="delRole(obj.row.id)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { successMsg } from "../../tools/tools.js";
import { roleDelete } from "../../request/api.js";
export default {
  props: ["tableData"],
  data() {
    return {};
  },
  methods: {
    updateRole(id) {
      this.$emit("updateRole", id);
    },
    delRole(id) {
      //删除角色
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        roleDelete({ id })
          .then((d) => {
            if (d.data.code == 200) {
              //调用接口成功时执行
              successMsg("删除成功");
              this.$emit("roleaddrefls"); //给父组件绑定事件 重新加载页面数据
              console.log(d);
            }
          })
          .catch((e) => {
            console.log(e);
          });
      }).catch(e=>{
        
      });
    },
  },
};
</script>

<style>
.cell {
  text-align: center !important;
}
</style>